﻿Public Class NganHangForm
    Dim dt As DataTable
    Private Sub ChiPhiForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        dt = NganHangDAO.GetAll()
        dgNganHang.DataSource = dt
        dgNganHang.Columns(1).HeaderText = "Tên ngân hàng"
        dgNganHang.Columns(0).Visible = False
    End Sub

    Private Sub btExit_Click(sender As System.Object, e As System.EventArgs) Handles btExit.Click
        Me.DialogResult = Windows.Forms.DialogResult.OK
        Me.Hide()
    End Sub

    Private Sub dgChiPhi_CellClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgNganHang.CellClick
        txtTen.Text = dt.Rows(dgNganHang.CurrentRow.Index).Item("Ten").ToString()
    End Sub

    Private Sub btThem_Click(sender As System.Object, e As System.EventArgs) Handles btThem.Click
        If txtTen.Text.Trim().Length = 0 Then
            MessageBox.Show("Xin vui lòng nhập vào tên")
            Return
        End If
        Dim dr As DataRow = dt.NewRow()
        dr("Ten") = txtTen.Text
        dt.Rows.Add(dr)
        DB_Provider.Write(dt, "NganHang")
    End Sub

    Private Sub btXoa_Click(sender As System.Object, e As System.EventArgs) Handles btXoa.Click
        If dt.Rows.Count > 0 Then
            dt.Rows(dgNganHang.CurrentRow.Index).Delete()
            DB_Provider.Write(dt, "NganHang")
        End If
    End Sub

    Private Sub btSua_Click(sender As System.Object, e As System.EventArgs) Handles btSua.Click
        If txtTen.Text.Trim().Length = 0 Then
            MessageBox.Show("Xin vui lòng nhập vào tên")
            Return
        End If
        Dim index As Integer = dgNganHang.CurrentRow.Index
        If (index > -1) Then
            dt.Rows(index).Item("Ten") = txtTen.Text
            DB_Provider.Write(dt, "NganHang")
        End If
    End Sub
End Class